<template>
  <view class="mediator-container">
    <!-- 基本信息卡片 -->
    <view class="base-info-card" :class="{ 'is-offline': !isOnline }">
      <view class="card-header">
        <text class="title">专属媒人</text>
        <view class="status-tag">
          <view class="status-badge" :class="isOnline ? 'online' : 'offline'">
            <view class="pulse-dot" v-if="isOnline"></view>
            {{ isOnline ? '在线' : '离线' }}
          </view>
          <view class="rating">
            <text class="star">★</text>
            <text class="score">{{ data.rating  || '4.8' }}</text>
          </view>
        </view>
      </view>
 
      <view class="card-body">
        <view class="avatar-container">
          <image 
            class="avatar"
            :src="data.avatar  || '/static/default-mediator.png'" 
            mode="aspectFill"
          />
          <view v-if="!isOnline" class="offline-dot"></view>
        </view>
 
        <view class="info-content">
          <text class="name">{{ data.name  || '未分配' }}</text>
          
          <button 
            v-if="data.phone" 
            class="contact-btn"
            :class="{ 'online': isOnline, 'offline': !isOnline }"
            @click="handleCall"
          >
            <text class="icon-phone">📞</text>
            {{ isOnline ? '立即联系' : '留言' }}
          </button>
        </view>
      </view>
 
      <view v-if="!isOnline" class="offline-mask">
        <text>媒人当前离线，可留言或稍后联系</text>
      </view>
    </view>
 
    <!-- 详细信息卡片 -->
    <view class="detail-info-card">
      <view class="card-header">
        <text class="title">服务信息</text>
      </view>
 
      <view class="stats-container">
        <view class="stat-item">
          <text class="number">{{ data.serviceYears  || 0 }}</text>
          <text class="label">年经验</text>
        </view>
        <view class="stat-item">
          <text class="number">{{ data.successCount  || 0 }}</text>
          <text class="label">对成功</text>
        </view>
        <view class="stat-item">
          <text class="number">{{ data.successRate  || '30%' }}</text>
          <text class="label">成功率</text>
        </view>
      </view>
 
      <view class="tags-container">
        <view 
          v-for="(tag, index) in displayTags"
          :key="index"
          class="tag"
        >
          {{ tag }}
        </view>
      </view>
 
      <view class="footer-actions">
        <view class="service-time">
          <text class="icon-clock">🕒</text>
          <text>服务时间: {{ data.serviceTime  || '9:00-18:00' }}</text>
        </view>
        <button 
          v-if="showReplace"
          class="replace-btn"
          @click="handleReplace"
        >
          更换媒人 
        </button>
      </view>
    </view>
  </view>
</template>
 
<script>
export default {
  props: {
    data: {
      type: Object,
      default: () => ({})
    },
    showReplace: {
      type: Boolean,
      default: true 
    },
    forceOnline: {
      type: Boolean,
      default: false 
    }
  },
  computed: {
    displayTags() {
      return this.data.tags  ? this.data.tags.slice(0,  3) : ['资深', '耐心'];
    },
    isOnline() {
      if (this.forceOnline)  return true;
      return Math.random()  > 0.3;
    }
  },
  methods: {
    handleCall() {
      uni.makePhoneCall({   
        phoneNumber: this.data.phone,   
        fail: () => {
          uni.showToast({  
            title: '拨打失败，请检查号码',
            icon: 'none'
          });
        }
      });
    },
    handleReplace() {
      this.$emit('replace', this.data.id);   
    }
  }
};
</script>
 
<style lang="scss" scoped>
.mediator-container {
  padding: 24rpx;
}
 
.base-info-card {
  position: relative;
  padding: 32rpx;
  background: linear-gradient(135deg, #FFFFFF 0%, #F8F9FA 100%);
  border-radius: 24rpx;
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.06);
  margin-bottom: 24rpx;
  overflow: hidden;
  transition: all 0.3s ease;
  border: 1rpx solid rgba(0, 0, 0, 0.04);
 
  &.is-offline {
    opacity: 0.9;
    background: linear-gradient(135deg, #F5F5F5 0%, #EEEEEE 100%);
  }
 
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32rpx;
 
    .title {
      font-size: 36rpx;
      font-weight: 700;
      color: #333;
      position: relative;
      padding-left: 16rpx;
      
      &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 6rpx;
        bottom: 6rpx;
        width: 4rpx;
        background: linear-gradient(to bottom, #2196F3, #00BCD4);
        border-radius: 2rpx;
      }
    }
 
    .status-tag {
      display: flex;
      align-items: center;
      gap: 16rpx;
 
      .status-badge {
        padding: 6rpx 16rpx;
        border-radius: 20rpx;
        font-size: 24rpx;
        font-weight: 500;
        position: relative;
        
        &.online {
          background: rgba(76, 175, 80, 0.15);
          color: #4CAF50;
        }
 
        &.offline {
          background: rgba(33, 150, 243, 0.15);
          color: #2196F3;
        }
 
        .pulse-dot {
          position: absolute;
          width: 8rpx;
          height: 8rpx;
          background: #4CAF50;
          border-radius: 50%;
          right: 10rpx;
          top: 50%;
          transform: translateY(-50%);
          animation: pulse 1.5s infinite;
        }
      }
 
      .rating {
        display: flex;
        align-items: center;
        font-size: 26rpx;
        color: #FF9800;
        font-weight: 500;
        
        .star {
          margin-right: 4rpx;
          font-size: 28rpx;
        }
      }
    }
  }
 
  .card-body {
    display: flex;
    align-items: center;
 
    .avatar-container {
      position: relative;
      width: 120rpx;
      height: 120rpx;
      margin-right: 24rpx;
      flex-shrink: 0;
 
      .avatar {
        width: 100%;
        height: 100%;
        border-radius: 16rpx;
        background: #f5f5f5;
        box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
        border: 2rpx solid rgba(255, 255, 255, 0.8);
      }
 
      .offline-dot {
        position: absolute;
        right: -6rpx;
        top: -6rpx;
        width: 16rpx;
        height: 16rpx;
        border-radius: 50%;
        background: #9E9E9E;
        border: 2rpx solid #FFFFFF;
        box-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.1);
      }
    }
 
    .info-content {
      flex: 1;
      display: flex;
      flex-direction: column;
 
      .name {
        font-size: 36rpx;
        font-weight: 600;
        color: #333;
        margin-bottom: 20rpx;
      }
 
      .contact-btn {
        height: 64rpx;
        padding: 0 28rpx;
        border-radius: 32rpx;
        font-size: 28rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        border: none;
        outline: none;
        transition: all 0.3s ease;
        box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
        
        .icon-phone {
          margin-right: 8rpx;
          font-size: 28rpx;
        }
 
        &.online {
          background: linear-gradient(to right, #2196F3, #00BCD4);
          color: #FFFFFF;
          
          &:active {
            transform: scale(0.98);
            opacity: 0.9;
          }
        }
 
        &.offline {
          background: #EEEEEE;
          color: #757575;
        }
      }
    }
  }
 
  .offline-mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.88);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 28rpx;
    color: #616161;
    backdrop-filter: blur(4px);
    z-index: 2;
  }
}
 
.detail-info-card {
  padding: 32rpx;
  background: #FFFFFF;
  border-radius: 24rpx;
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.06);
  border: 1rpx solid rgba(0, 0, 0, 0.04);
 
  .card-header {
    margin-bottom: 28rpx;
 
    .title {
      font-size: 32rpx;
      font-weight: 600;
      color: #333;
      position: relative;
      padding-left: 16rpx;
      
      &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 6rpx;
        bottom: 6rpx;
        width: 4rpx;
        background: linear-gradient(to bottom, #FF9800, #FFC107);
        border-radius: 2rpx;
      }
    }
  }
 
  .stats-container {
    display: flex;
    justify-content: space-around;
    margin: 32rpx 0;
    padding: 24rpx 0;
    background: rgba(248, 249, 250, 0.6);
    border-radius: 16rpx;
 
    .stat-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
 
      .number {
        font-size: 40rpx;
        font-weight: 700;
        color: #2196F3;
        margin-bottom: 8rpx;
        background: linear-gradient(to right, #2196F3, #00BCD4);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }
 
      .label {
        font-size: 26rpx;
        color: #757575;
      }
    }
  }
 
  .tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 16rpx;
    margin: 24rpx 0;
 
    .tag {
      padding: 8rpx 20rpx;
      background: rgba(33, 150, 243, 0.1);
      border-radius: 24rpx;
      font-size: 26rpx;
      color: #2196F3;
      transition: all 0.3s ease;
      
      &:active {
        transform: scale(0.96);
        background: rgba(33, 150, 243, 0.2);
      }
    }
  }
 
  .footer-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 24rpx;
    border-top: 1rpx solid rgba(0, 0, 0, 0.05);
 
    .service-time {
      font-size: 26rpx;
      color: #9E9E9E;
      display: flex;
      align-items: center;
      flex: 1;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
 
      .icon-clock {
        margin-right: 8rpx;
        font-size: 28rpx;
      }
    }
 
    .replace-btn {
      height: 64rpx;
      padding: 0 32rpx;
      border-radius: 32rpx;
      font-size: 28rpx;
      background: transparent;
      color: #757575;
      border: 1rpx solid #E0E0E0;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.3s ease;
      
      &:active {
        background: rgba(0, 0, 0, 0.02);
        transform: scale(0.98);
      }
    }
  }
}
 
@keyframes pulse {
  0% {
    transform: translateY(-50%) scale(1);
    opacity: 1;
  }
  70% {
    transform: translateY(-50%) scale(1.5);
    opacity: 0.7;
  }
  100% {
    transform: translateY(-50%) scale(2);
    opacity: 0;
  }
}
</style>